package view.table;

import java.awt.Component;
import java.awt.Image;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

import view.ResourceBundleWrapper;

public class ExchangerTableRenderer extends DefaultTableCellRenderer {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private ResourceBundleWrapper resourceBundleWrapper;
	
	public ExchangerTableRenderer(ResourceBundleWrapper resourceBundleWrapper){
		super();
		this.resourceBundleWrapper = resourceBundleWrapper;
	}

	public Component getTableCellRendererComponent(JTable table,
			Object value, boolean isSelected, boolean hasFocus, int row,
			int column) {
		if (value instanceof String){
			JLabel label;
			//si on est dans la seconde colonne il s'agit d'image
			if(column == 1){
				ImageIcon icon =new ImageIcon((String)value);
	        	icon.setImage(icon.getImage().getScaledInstance(15, 13, Image.SCALE_DEFAULT));
				label = new JLabel(icon);
			}
			//si on est dans la troisieme il s'agit des noms des monnaies
			else if(column == 2){
				String keyName = ((String)value).replaceAll(" ", "");
				label = new JLabel(this.resourceBundleWrapper.getString(keyName));
			}
			else{
				label = new JLabel((String)value);
			}
			return label;
		}
		else
			return this;
	}

}
